<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<title>Rapyd Library Guide</title>

<style type='text/css' media='all'>@import url('../userguide.css');</style>
<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />

<script type="text/javascript" src="../nav/nav.js"></script>
<script type="text/javascript" src="../nav/prototype.lite.js"></script>
<script type="text/javascript" src="../nav/moo.fx.js"></script>
<script type="text/javascript" src="../nav/syntax.js"></script>
<script type="text/javascript" src="../nav/syntax_php.js"></script>
<link type="text/css" href="../syntax.css" rel="stylesheet" /></head>
<body>

<!-- START NAVIGATION -->
<script type="text/javascript">create_header('../');</script>
<!-- END NAVIGATION -->


<!-- START BREADCRUMB -->
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td id="breadcrumb">
<a href="http://www.rapyd.com/">Rapyd Library Home</a> &nbsp;&#8250;&nbsp;
<a href="../index.html">Rapyd Guide</a> &nbsp;&#8250;&nbsp;
Rapyd Session Class
</td>
<td id="searchbox">
<script type="text/javascript">create_search();</script>
</td>
</tr>
</table>
<!-- END BREADCRUMB -->

<br clear="all" />


<!-- START CONTENT -->
<div id="content">


<h1>Rapyd Session Class</h1>

<p class="important"><strong>Important:</strong>&nbsp;
Code Igniter session class is cookie based, does not utilize native PHP sessions.<br/>
Rapyd Session class instead use native PHP sessions.
</p>

<p>
Rapyd Session class is derived from an old version of <a href="http://www.codeigniter.com/wiki/Native_session/">Native Session</a>. So basically is a PHP session ($_SESSION) reader/writer.<br />
You can use this reference: <kbd>$this->rapyd->session</kbd>.
</p>

<p>
It support var namespaces:
</p>

<textarea name="code" class="php:nogutter:nocontrols" rows="15" cols="100">
$this->rapyd->session->set("var", "value" [, "namespace"]);
$this->rapyd->session->get("var"); 
$this->rapyd->session->clear("var");
</textarea>

<h2>Components Persistence</h2>
<p>
It support persistence engine (store page status of $_POST, and uri segments).<br/>
This is used in conjunction with <a href="uri">rapyd uri</a>.
</p>
<p>
The idea of persistence is to keep component status (i.e. DataFilter input values, DataGrid page offset) for each controller/uri.
</p>
<p>
Rapyd build this kind of structure:
</p>
<pre>
array (
  'rapyd' => 
  array (
    'language' => 'english',
    'rapyd/crudsamples/filteredgrid' => 
    array (
      'bbhcfblliebc' => 
      array (
        'back_post' => 'a:0:{}',
        'back_uri' => 'rapyd/crudsamples/filteredgrid/gfid/bbhcfblliebc/osp',
        'expire' => 1172520216
      ),
      'bbhcfbleafca' => 
      array (
        'back_post' => 'a:0:{}',
        'back_uri' => 'rapyd/crudsamples/filteredgrid/gfid/bbhcfbleafca/osp',
        'expire' => 1172521234
      ),
      ..... others concurrent sessions
    )
    ... others uri 
  )
)
</pre>

<p>
So, for each "base_uri" (controller/function/customparams) rapyd "can" store the needed data.
</p>
<ul>
<li><strong>back_uri</strong> is the complete uri from where the persistence entry has been generated</li>
<li><strong>back_post</strong> is a serialized $_POST from where the entry has been generated</li>
<li><strong>expire</strong> is the timestamp of expiration (see settings at the bottom of the page)</li>
</ul>
<p>
<strong>gfid/bbhcfbleafca</strong> in the uri is an Alphabetical "session index".<br/>
It's autogenerated by rapyd components, and each link/button keep it alive.
</p>
<p class="important">
Alphabetical index ("bbhcfblliebc","bbhcfbleafca"...) are thinked to give the possibility to use more instances of browser, without session overriding problems<br/>
Normally, if you do that, you have the same "php session_id" (and so.. all session variables) shared in each browser instance (think to firefox tabs for example).<br/>
Rapyd Components persistence is thinked to work even in this situation.
This is not a common feature, it can be really useful for wide crud applications (like intranets, cms administrations).
</p>
<p>
Alphabetical index ("bbhcfblliebc","bbhcfbleafca"...) aren't random strings, they are a timestamp (or better a microtime) encoded as string.
This make possible to clear old sessions in an easy way.
</p>


<h2>Session Reference</h2>

<kbd>$this->rapyd->session</kbd> (by default is instanced with rapyd, on library load).

<h5>Settings</h5>

<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
<tr>
  <th>Property</th>
  <th>Default&nbsp;Value</th>
  <th>Options</th>
  <th>Description</th>
</tr>
<tr>
  <td><strong>persistence_duration</strong></td>
  <td>240</td>
  <td>numeric</td>
  <td>max persistence duration(seconds)</td>
</tr>
<tr>
  <td><strong>persistence_limit</strong></td>
  <td>10</td>
  <td>numeric</td>
  <td>max number of concurrent sessions per uri.</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
</table>
<p class="important"><strong>Important:</strong>&nbsp;
These properties are stored in /system/application/config/rapyd.php
</p>


<h5>Methods</h5>

<p>
<strong>
 $this->rapyd->session->set($var, $value [, $namespace]);
</strong>
</p>
<p>
do: $_SESSION["namespace"]["var"] = "value";
</p>
<br/>

<p>
<strong>
  $this->rapyd->session->get($var [, $namespace]);
</strong>
</p>
<p>
return the value of the flash var $var
</p>
<br/>

<p>
<strong>
  $this->rapyd->session->clear($var [, $namespace]);
</strong>
</p>
<p>
do: unset($_SESSION[$namespace][$var]);
</p>
<br/>

<p>
<strong>
  $this->rapyd->session->save_persistence($uri, $page=null, $microtime=null);
</strong>
</p>
<p>
Basically you will never use persistence methods directly,  because they are called directly by rapyd components.<br/>
However, If you need to extend rapyd a reference can help.<br/>
This method store a entry in $_SESSION like you've seen above. So for a given $uri, it can store the page data ($page).<br/>
If $microtime is passed, it will be used as sub_index (remember: $microtime is an encoded version of a numeric timestamp/microtime).<br/>
Otherwise $microtime will be generated by the function and the function will return it. So you can find it with get_persistence (next method)
</p>
<br/>

<p>
<strong>
  $this->rapyd->session->get_persistence($uri, $microtime=null);
</strong>
</p>
<p>
This method return a saved $page array (see prev method), by passing a $uri and optionally a $microtime.<br/>
If no $microtime is passed, the method try to find th most recent entry for the given $uri.
</p>


</div>
<!-- END CONTENT -->


<script type="text/javascript">create_footer();</script>

</body>
</html>